package com.leyou.item.service;

import com.leyou.item.mapper.SpecGroupMapper;
import com.leyou.item.mapper.SpecParamMapper;
import com.leyou.item.pojo.SpecGroup;
import com.leyou.item.pojo.SpecParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SpecGroupService {

    @Autowired
    SpecGroupMapper sgm;
    @Autowired
    SpecParamMapper specParamMapper;

    public List<SpecGroup> querySpecGroupByCid(Long cid) {
        SpecGroup specGroup = new SpecGroup();
        specGroup.setCid(cid);
        List<SpecGroup> list = sgm.select(specGroup);
        return list;
    }

    public List<SpecGroup> querySpecGroupAndParamByCid(Long cid) {
        SpecGroup specGroup = new SpecGroup();
        specGroup.setCid(cid);
        List<SpecGroup> list = sgm.select(specGroup);
        list.forEach(l->{
            SpecParam specParam = new SpecParam();
            specParam.setGroupId(l.getId());
            List<SpecParam> params = specParamMapper.select(specParam);
            l.setParams(params);
        });
        return list;
    }
}
